package com.itheima.dao;

import com.itheima.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Results(
            value = {
                    @Result(id = true, column = "id", property = "id"),
                    @Result(id = true, column = "user_name", property = "username"),
                    @Result(id = true, column = "home_address", property = "address"),
                    @Result(
                            property = "userInfo",
                            column = "id",
                            one = @One(select = "com.itheima.dao.UserInfoMapper.selectUserInfoByUserId")
                    ),
                    @Result(
                            property = "orders",
                            column = "id",
                            many = @Many(select = "com.itheima.dao.OrderMapper.selectOrderByUserId")
                    )
            }
    )

    /**
     * 一对多
     */
    @Select(value="select * from t_user where id = #{id}")
    User selectOrderById(@Param("id") Integer id);

    /**
     * 一对一
     */
    @Select(value="select * from t_user where id = #{id}")
    User selectById(@Param("id") Integer id);


    /**
     * 根据姓名模糊查询
     * @param username
     * @return
     */
    @Select(value = "select * from t_user where user_name like concat ('%',#{username},'%')")
    List<User> selectByLike(String username);


    /**
     * 分页查询
     *
     * @param startIndex
     * @param pageSize
     * @return
     */
    @Select(value = "select * from t_user limit #{param1}, #{param2}")
    List<User> selectByPage1(Integer startIndex, Integer pageSize);
}

